package chpt12;

import java.sql.*;

public class DBbasic5UpdateableRS {
	public static void main(String[] args) {
		String url = "jdbc:mysql://127.0.0.1:3306/demoDB?serverTimezone=Asia/Chongqing";
		String userName = "root";
		String pwd = "root123";
		String sql = "select * from students where gpa<2";
		try (Connection con = DriverManager.getConnection(
				url, userName, pwd);
				Statement stmt = con.createStatement(
						ResultSet.TYPE_FORWARD_ONLY, 
						ResultSet.CONCUR_UPDATABLE);){
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
				rs.updateDouble(4, 2); // 把gpa<2的gpa都改为2
				rs.updateRow(); // 必须这句才能生效
			}
			System.out.println("完成更新！");

		} catch (SQLException e) {
			e.printStackTrace();
		} 
	}
}
